class Company(object):
    def __init__(self, employee_list):
        self.employee = employee_list

    def __getitem__(self, item):
        return self.employee[item]

    def __len__(self):
        return len(self.employee)

company = Company(["tom", "bob", "jane"])

# for em in company.employee:
#     print(em)

# 切片操作
company1 = company[:2]      # 背后是使用的__getitem__魔法函数
print(company1)

# 使用len()函数
print(len(company))         # 会报错：TypeError: object of type 'Company' has no len()
                            # Company对象要想使用len()，则需要实现__len__魔方函数

print(len(company1))        # 2。因为compamy1本身是list，所以可以使用len()


# for遍历Company对象
for em in company:
    print(em)